//suplimentary homework 1 from Wenbo Su
#include <iostream>
#include <string>
using namespace std;

class determinant 
{
public:
	determinant();
	int evaluateDeterminant(int A[][3]);
	~determinant();
private:
	int array[3][3];
	int dimension;
};

determinant::determinant(){		//define constructor
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			array[i][j] = 0;
		}
	}
	dimension = 0;
}
int determinant::evaluateDeterminant(int A[][3]){	//define a function to evaluate determinant
	int result;
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			array[i][j] = A[i][j];
		}
	}
	//fomular for 3 dimension determinat
	result = array[0][0]*array[1][1]*array[2][2] + array[0][1]*array[1][2]*array[2][0] + array[0][2]*array[1][0]*array[2][1] - array[0][0]*array[1][2]*array[2][1] - array[0][1]*array[1][0]*array[2][2] - array[0][2]*array[1][1]*array[2][0];
	return result;
}

determinant::~determinant(){	//define destructor
	cout<<"system is done!"<<endl;
}

int main()
{
	int n = 3;
	int value;
	determinant *determinantObject = new determinant;	//crate a object and assign heap memory
		int Array[3][3];
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				cout <<"Please input Array["<<i<<"]["<<j<<"]'s value for a determinant of dimension = 3:";
				cin >> value;
				if (!cin.eof() && cin.good())	//check if input are correct
				{
					Array[i][j] = value;
				}
				else if (!cin.good())	//stop program if input non-integer value.
				{
					cout<<"You just input a invalid array value!"<< endl;
					delete determinantObject;
    				exit(1);
    				return 0;
				}
				else	//stop ptogram if put eof
				{
					cout<<"You input EOF and terminate program."<<endl;
					delete determinantObject;
    				exit(1);
    				return 0;
				}
			}
		}
    	cout<<"This is the determinant you just entered:"<<endl;
    	for (int i = 0; i < n; ++i)
    	{
    		for (int j = 0; j < n; ++j)
    		{
    			cout<<Array[i][j]<<" ";
    		}
    		cout<<endl;
    	}
    	//call function evaluateDeterminant to evaluate determinat's value
    	cout<<"The evaluation of determinant is:"<<determinantObject->evaluateDeterminant(Array)<<endl;
    	delete determinantObject;	//assign this memory free
    	return 0;  
}    